home *** CD-ROM | disk | FTP | other *** search
/ Creative Review 28 / Creative-Review-CD-ROM-28.iso / pc / kungfu / assets / game.dir / 00003_Script_cell manager class < prev    next >
Text File  |  1997-08-08  |  8KB  |  325 lines

  1. -- cell manager class
  2. -- --------------------------------------------------
  3. -- for 0.1m
  4. -- can hold more than more actor in each cell
  5. -- --------------------------------------------------
  6.  
  7. property cellsize
  8. property celllist
  9. property actorwidth
  10. property celloffset
  11.  
  12. property floor 
  13.  
  14. property offsetlist
  15.  
  16. -- ==================================================
  17. -- new method
  18. -- --------------------------------------------------
  19. on new me
  20.   
  21.   minit me
  22.   return me
  23.   
  24. end mnew 
  25.  
  26. -- ==================================================
  27. -- minit method
  28. -- --------------------------------------------------
  29. on minit me
  30.   
  31.   set celloffset =  5
  32.   set cellsize = 20
  33.   set actorwidth = 4
  34.   
  35.   set floor = 280
  36.   
  37.   set offsetlist = data2list ( "offset" )
  38.   
  39.   mclean me
  40.   
  41. end minit
  42.  
  43. -- ==================================================
  44. -- mclean method
  45. -- --------------------------------------------------
  46. on mclean me
  47.   
  48.   set celllist = []
  49.   repeat with index = 1 to 50
  50.     add celllist, []
  51.   end repeat
  52.   
  53. end mclean
  54.  
  55. -- ==================================================
  56. -- mscreen2cell method
  57. -- --------------------------------------------------
  58. on mscreen2cell me, loc
  59.   
  60.   return (( loc  ) / cellsize ) 
  61.   
  62. end mscreen2cell
  63.  
  64. -- ==================================================
  65. -- mcell2screen method
  66. -- --------------------------------------------------
  67. on mcell2screen me, loc
  68.   
  69.   return (loc ) * cellsize 
  70.   
  71. end mcell2screen
  72.  
  73. -- ==================================================
  74. -- mget method
  75. -- --------------------------------------------------
  76. on mget me, cellnumber
  77.   
  78.   set index = cellnumber + celloffset
  79.   return getat ( celllist, index )
  80.   
  81. end mget
  82.  
  83. -- ==================================================
  84. -- madd method
  85. -- --------------------------------------------------
  86. on madd me, cellnumber, who
  87.   
  88.   -- put "in mset cell"
  89.   
  90.   set thecell = mget ( me, cellnumber )
  91.   
  92.   add thecell, who
  93.   
  94.   -- put "out mset cell"
  95.   
  96. end madd
  97.  
  98. -- ==================================================
  99. -- mdelete method
  100. -- --------------------------------------------------
  101. on mdelete me, cellnumber, who
  102.   
  103.   -- put "in mdelete cell"
  104.   
  105.   set thecell = mget ( me, cellnumber )
  106.   
  107.   deleteone thecell, who
  108.   
  109.   -- put "in mdelete cell"
  110.   
  111. end mdelete
  112.  
  113. -- ==================================================
  114. -- mbatchdelete method
  115. -- --------------------------------------------------
  116. on mbatchdelete me, leftcell, who
  117.   
  118.   --  put "in mbatchdelete "
  119.   
  120.   repeat with index = leftcell to leftcell + actorwidth - 1
  121.     mdelete me, index, who
  122.   end repeat
  123.   
  124.   --  put "out mbatchdelete "
  125.   
  126. end mbatchdelete
  127.  
  128. -- ==================================================
  129. -- mdeleteall method
  130. -- --------------------------------------------------
  131. on mdeleteall me,  who
  132.   
  133.   --  put "in mdeleteall "
  134.   
  135.   repeat with thecell in celllist
  136.     deleteone thecell, who
  137.   end repeat
  138.   
  139.   --  put "out mdeleteall "
  140.   
  141. end mdeleteall
  142.  
  143. -- ==================================================
  144. -- mbatchadd method
  145. -- --------------------------------------------------
  146. on mbatchadd me, leftcell, who
  147.   
  148.   --  put "ò in mbatchadd cell"  leftcell, who
  149.   
  150.   repeat with index = leftcell to leftcell + actorwidth - 1
  151.     madd me, index, who
  152.   end repeat
  153.   
  154.   --  put "òáout mbatchadd cell"
  155.   
  156. end mbatchadd
  157.  
  158. -- ==================================================
  159. -- mbatchadd method
  160. -- --------------------------------------------------
  161.  
  162. on mjump me, who, oldleftcell, direction
  163.   
  164.   --  put "in mjump cell"  oldleftcell, who
  165.   
  166.   mbatchdelete me, oldleftcell, who
  167.   
  168.   case direction of:
  169.     #left: set newleftcell = oldleftcell - 8
  170.     #right: set newleftcell = oldleftcell + 8
  171.   end case
  172.   
  173.   mbatchadd me, newleftcell, who
  174.   
  175.   --  put "out mjump cell"
  176.   
  177.   
  178. end mjump 
  179.  
  180. -- ==================================================
  181. -- mstartwalk method
  182. -- --------------------------------------------------
  183. on mstartwalk me, who, oldleftcell, direction
  184.   
  185.   -- put "in mstartwalk cell",  who, oldleftcell, direction
  186.   
  187.   case direction of
  188.     #right: set cellnumber =  oldleftcell + actorwidth
  189.     #left:set cellnumber =  oldleftcell - 1
  190.   end case
  191.   
  192.   madd me, cellnumber, who
  193.   
  194.   -- put "out mstartwalk cell"
  195.   
  196. end mstartwalk
  197.  
  198. -- ==================================================
  199. -- mfinishwalk method
  200. -- --------------------------------------------------
  201. on mfinishwalk me, who, oldleftcell, direction
  202.   
  203.   --  put "in mfinishwalk cell", who, oldleftcell, direction
  204.   
  205.   case direction of
  206.     #right: set cellnumber = oldleftcell   
  207.     #left: set cellnumber = oldleftcell + actorwidth - 1
  208.   end case
  209.   
  210.   mdelete me, cellnumber, who
  211.   
  212.   -- put "out mfinishwalk cell"
  213.   
  214. end mfinishwalk
  215.  
  216. -- ==================================================
  217. -- mbatchcheck method
  218. -- --------------------------------------------------
  219. on mbatchcheck me, leftcell, filterlist
  220.   
  221.   set batchwho = []
  222.   
  223.   if not ( listp ( filterlist )) then set filterlist = []
  224.   
  225.   repeat with index = leftcell to ( leftcell + actorwidth - 1 )
  226.     
  227.     set thiswho = mcheck ( me, index, #none )
  228.     
  229.     repeat with who in thiswho
  230.       if not ( getone ( filterlist, who )) and ¼
  231.          not ( getone ( batchwho, who )) then add ( batchwho, who )  
  232.     end repeat
  233.     
  234.   end repeat
  235.   
  236.   return batchwho
  237.   
  238. end mbatchcheck
  239.  
  240. -- ==================================================
  241. -- mcheck method
  242. -- --------------------------------------------------
  243. on mcheck me, leftcell, direction
  244.   
  245.   -- put "in mcheck cell " , me, leftcell, direction
  246.   
  247.   case direction of
  248.     #none: set newcell = leftcell
  249.     #right: set newcell = leftcell + actorwidth
  250.     #left:  set newcell = leftcell - 1
  251.   end case
  252.   
  253.   set who = mget ( me, newcell )
  254.   return who
  255.   
  256. end mcheck me
  257.  
  258. -- ==================================================
  259. -- mshow method
  260. -- --------------------------------------------------
  261. on mshow me
  262.   
  263.   put "in mshow cell"
  264.   
  265.   put "-----------------------"
  266.   
  267.   repeat with index = 1 to count ( celllist )
  268.     put (index - celloffset ), getat ( celllist , index )  
  269.   end repeat
  270.   
  271.   put "-----------------------"
  272.   
  273.   put "out mshow cell"
  274.   
  275. end mshow
  276.  
  277.  
  278. -- ==================================================
  279. -- mgetstartoffset method
  280. -- --------------------------------------------------
  281. on mgetstartoffset me, direction, data
  282.   
  283.   --  put "in mgetstartoffset cell manager class :"
  284.   
  285.   set list = getaprop ( offsetlist, data )
  286.   set startlist = getaprop ( list, #start )
  287.   set offset = getaprop ( startlist , direction )
  288.   
  289.   return offset
  290.   
  291.   --  put "out mgetstartoffset cell manager class :"
  292.   
  293. end mgetstartoffset
  294.  
  295.  
  296. -- ==================================================
  297. -- mgetflingoffset method
  298. -- --------------------------------------------------
  299. on mgetflingoffset me, direction, data
  300.   
  301.   --  put "in mgetflingoffset cell manager class :"
  302.   
  303.   set list = getaprop ( offsetlist, data )
  304.   set flinglist = getaprop ( list, #fling )
  305.   set offset = getaprop ( flinglist , direction )
  306.   
  307.   return offset
  308.   
  309.   --  put "out mgetflingoffset cell manager class :"
  310.   
  311. end mgetflingoffset
  312.  
  313. -- ==================================================
  314. -- mgetfloor method
  315. -- --------------------------------------------------
  316. on mgetfloor me
  317.   
  318.   --  put "in mgetfloor cell manager class :"
  319.   
  320.   return floor
  321.   
  322.   --  put "out mgetfloor cell manager class :"
  323.   
  324. end mgetfloor
  325.